home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0236_Toolbar Registering Example.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-05  |  2.1 KB  |  55 lines

  1. { Windows95/NT Toolbar registering example }
  2. { 2/13/97 by Brandon Sneed (Nivenh)}
  3. { If you use this, don't give me credit }
  4.  
  5.  
  6. { Add ShellAPI to your Uses clause }
  7.  
  8. { This code was pulled from an app i wrote and has been modified to make
  9.     it a little more understandable for those 'not-so-fluent' delphi coders }
  10.  
  11. { I put it in the OnShow event, but it probably could go in the create event
  12.     too maybe.. or anywhere else for that matter }
  13. procedure TForm1.OnShow(Sender: TObject);
  14. var Result : integer;
  15.         BarData : TAppBarData;
  16. begin
  17.  
  18. with BarData do
  19.   begin
  20.   cbSize := SizeOf(BarData);  { Size of the struct }
  21.   hwnd := OWForm.Handle;      { Window handle to register as app bar }
  22.   uCallBackMessage := WM_USER;{ Message used for APPBAR specific messages }
  23.   uEdge := ABE_LEFT;          { Side of screen to bind with }
  24.   rc := Rect(0, 0, OWForm.Width+1, OWForm.Height);
  25.                               {^^ Rectangle being requested to use }
  26.   lParam := 0;                { Only used for ABM_AUTOHIDEBAR }
  27.   end;
  28.  
  29. Result := SHAppBarMessage(ABM_NEW, BarData);  { Register with explorer }
  30. if Result = 0 then
  31.   begin
  32.   ShowMessage('Unable to register AppBar.');
  33.   exit;
  34.   end;
  35.  
  36. SHAppBarMessage(ABM_QUERYPOS, BarData); { Can we use BarData.RC ?? }
  37.                                                                                 { API wasn't clear on what this returned }
  38. SHAppBarMessage(ABM_SETPOS, BarData);   { Set the position to be the same as in RC }
  39. { ^^ this is what makes everything fall into place }
  40.  
  41. with OWForm do
  42.   begin
  43.   Application.ProcessMessages; { Without this, it places in the wrong spot, could
  44.                                                                  be an error on my part somewhere }
  45.   SetWindowPos(Handle, HWND_BOTTOM, left-width, top, width, height, SWP_NOREDRAW);
  46.   { ^^ this sets the window where we want it.  at the very left edge of the screen }
  47.     { modify this line to suit }
  48.   end;
  49. end;
  50.  
  51. { NOTE:  This ONLY reigsters it as a toolbar and places it in the appropriate
  52.     spot.  You still need to make handlers for the other ABE/ABM messages.
  53.     See the documentation in Delphi 2.0 and up for more info.  Look up
  54.     SHAppBarMessage }
  55.